#include "XMLTree.h"
using namespace std;


XMLTree::XMLTree(string name, const Attributes &attrs) 
{
	elementName = name;
	for (int i=0; i< attrs.getLength(); i++) 	
	{
		elementAttributes[string(XMLString::transcode(attrs.getQName(i)))] = string(XMLString::transcode(attrs.getValue(i)));
	}
}

XMLTree::~XMLTree()
{
	elementAttributes.clear();
	childElements.clear();
}

XMLTree::XMLTree(string name, map<string,string> &attrs) 
{
	elementName = name;
	for(map<string, string>::iterator iter = attrs.begin(); iter != attrs.end();iter++)
	{
		elementAttributes[iter->first] = iter->second;
	}

}


XMLTree * XMLTree::getChildElement(int x) 
{
	if (childElements.empty()) 
	{
		return NULL;
	}
	if (x >= childElements.size()) {
		return NULL;
	}
	int i = 0;	
	list<XMLTree*>::iterator iter = childElements.begin();
	while( i < x && iter != childElements.end())
	{
		iter++;
	} 
	return *iter;
}

